
<!--检验单据-->
<template>
    <div class="page-box">
        <div class="page-search">
            <div>
                <label>工序检验单编号</label>
                <el-input v-model="searchForm.RecordCode" style="width: 160px;" placeholder="请输入工序检验单编号"></el-input>
            </div>
            <div>
                <label>工序编号</label>
                <el-input v-model="searchForm.ProcessCode" style="width: 160px;" placeholder="请输入工序编号"></el-input>
            </div>
            <div>
                <label>报工人</label>
                <el-input v-model="searchForm.ReportUser" style="width: 160px;" placeholder="请输入报工人"></el-input>
            </div>
            <div>
                <el-button type="primary" @click="search">查询</el-button>
                <el-button @click="reset">重置</el-button>
            </div>
        </div>
        <div class="page-section">
            
            <div class="page-tool">
                <el-button type="primary" plain icon="el-icon-plus" @click="add" size="small">新增</el-button>
                <el-button type="danger" plain icon="el-icon-delete" @click="dels" size="small">删除</el-button>
            </div>
            
            <!--表单-->
            <el-table :data="tableData"  ref="dataForm"   v-loading="isLoading"  height="calc(100vh - 350px)" >
                
                <el-table-column  type="selection" width="55"></el-table-column>
                <el-table-column  prop="RecordCode" label="工序检验单编号" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="TaskCode" label="任务单号" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="OrderCode" label="订单编号" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="ProcessCode" label="工序编号" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="ProcessName" label="工序名称" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="Quantity" label="数量" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="ReportUser" label="报工人" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="InspectWay" label="检验方式" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="Version" label="版本" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column label="收订单日期" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <span>{{ scope.row.OrderDate | formatDateTime  }}</span>
                    </template>
                </el-table-column>
                <el-table-column  prop="Status" label="状态" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="InspectGroup" label="质检组" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column  prop="InspectUser" label="质检员" :show-overflow-tooltip="true"></el-table-column>
                

                <el-table-column   label="操作" :show-overflow-tooltip="true" width="160">
                    <template slot-scope="scope">
                        <el-button  type="text" @click="compare(scope.row)" v-if="model.Status=='0'">质检</el-button>
                        <el-button type="text" @click="details(scope.row)" v-if="model.Status=='1'">质检结果</el-button>
                        

                        <el-button type="text" @click="update(scope.row)">编辑</el-button>
                        <el-button type="text" @click="del(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
    

            <Pagination @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange" :PageIndex="pageDomain.PageIndex" :PageSize="pageDomain.PageSize" :TotalCount="pageDomain.TotalCount"/>
        </div>

        <el-dialog :close-on-click-modal="false" :title="dialogDomain.title" :visible.sync="dialogDomain.dialogVisible"
            width="60%" @close="closeDialog">
            <QcProcessRecordInput :model="model" :isUpdate="isUpdate" @callback="callback" v-if="dialogDomain.dialogVisible && dialogDomain.dialogType == 0"/>
        </el-dialog>


   </div>


</template>

<script>
import Pagination from '@/components/Pagination.vue';
import QcProcessRecordInput from './components/QcProcessRecordInput.vue';
export default {
    components:{
        Pagination,
        QcProcessRecordInput
    },
    mounted(){
        this.dataBind();
    },
    data(){
        return{

            //对话框对象
            dialogDomain: {
                title: '新增检验单据',
                dialogVisible: false,
                dialogType:0
            },

            //搜索字段
            searchForm:{
                RecordCode:'',
                ProcessCode:'',
                ReportUser:'',
            },
           
            //数据模型
            model:{
                RecordCode:'',
                TaskCode:'',
                OrderCode:'',
                ProcessCode:'',
                ProcessName:'',
                Quantity:'',
                ReportUser:'',
                InspectWay:'',
                Version:'',
                OrderDate:'',
                Status:'0',
                InspectGroup:'',
                InspectUser:'',

            },
            

            pageDomain:{
                PageIndex:1,
                PageSize:10,
                TotalCount:0
            },
            //表单数据
            tableData:[],

            isLoading:false,
            
            //判断是否修改状态
            isUpdate: false,


        }
    },
    methods:{
        //添加
        add() {
            this.dialogDomain.title = "新增检验单据";
            this.dialogDomain.dialogVisible = true;
            this.isUpdate=false;
            this.dialogDomain.dialogType=0;
        },
        //修改
        update(model){
            this.dialogDomain.title = "编辑检验单据";
            this.dialogDomain.dialogVisible = true;
            this.isUpdate = true;
            this.dialogDomain.dialogType=0;
            this.model = model;
        }, 
        //工序检验结果表
        compare(model){
            this.dialogDomain.title = "工序检验对比";
            this.dialogDomain.dialogVisible = true;
            this.dialogDomain.dialogType=1;
            this.model = model;
        },
        //工序检验结果表
        details(model){
            this.dialogDomain.title = "工序检验结果";
            this.dialogDomain.dialogVisible = true;
            this.dialogDomain.dialogType=2;
            this.model = model;
        }, 
        


        //批量删除
        dels(){
            if(this.$refs.dataForm.selection.length<=0){
                this.showNotify('请先选择一项')
                return;
            }
            this.$confirm('确定删除选中的数据吗？这将不可恢复, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
            .then(() => {
                
                //获取选中的表格数据 并筛选id
                var ids =this.$refs.dataForm.selection.map(x=>x.Id)

                //拼接参数
                let params =  new URLSearchParams();
                params.append('ids',ids.join(','))

                this.$http.delete('/api/QcProcessRecord/DelAll',{
                    data:params,
                    headers:{
                        'content-Type': 'application/x-www-form-urlencoded'
                    },
                    loading:this.$loading()
                })
                .then((res)=>{
                    this.showNotify('操作成功','success');
                    this.dataBind();
                })
            }).catch(()=>{});     
            
        },

        //删除单条
        del(model){
            this.$confirm('确定删除选中的数据吗？这将不可恢复, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
            .then(() => {
                this.$http.delete('/api/QcProcessRecord',{
                    data:{
                        id:model.Id
                    },
                    headers:{
                        'content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                .then((res)=>{
                    this.showNotify('操作成功','success');
                    this.dataBind();
                })
            }).catch(()=>{});  
        },

        //对话框关闭事件
        closeDialog() {
            this.model = {
                RecordCode:'',
                TaskCode:'',
                OrderCode:'',
                ProcessCode:'',
                ProcessName:'',
                Quantity:'',
                ReportUser:'',
                InspectWay:'',
                Version:'',
                OrderDate:'',
                Status:'0',
                InspectGroup:'',
                InspectUser:'',
            }
        },
        //新增或编辑页面回调
        callback(){
            let actionName = this.isUpdate?'编辑':'新增';
            this.showNotify(actionName+'检验单据成功','success');
            this.dialogDomain.dialogVisible=false;
            this.dataBind();
        },
        

        

        //查询
        search(){
            this.pageDomain.PageIndex=1;
            this.dataBind();
        },
        //重置查询输入框
        reset(){
            this.searchForm.RecordCode='';
            this.searchForm.ProcessCode='';
            this.searchForm.ReportUser='';
        },
        //分页方法
        handleSizeChange(val){
            this.pageDomain.PageIndex = 1;
            this.pageDomain.PageSize = val;
            this.dataBind();
        },
        handleCurrentChange(val){
            this.pageDomain.PageIndex = val;
            this.dataBind();
        },


        

        //获取数据
        dataBind(){
            this.isLoading=true;
            this.$http.get('/api/QcProcessRecord',
            {
               params:{
                    PageIndex:this.pageDomain.PageIndex,
                    PageSize:this.pageDomain.PageSize,
                    RecordCode:this.searchForm.RecordCode,
                    ProcessCode:this.searchForm.ProcessCode,
                    ReportUser:this.searchForm.ReportUser,
               }
            })
            .then(res=>{
                this.tableData=res.Data;
                this.pageDomain.TotalCount = res.Count;
                this.isLoading=false;
            })
        }
    }

}
</script>

<style>

 </style>